//InnerAudioContext实例
//const app = getApp()
//InnerAudioContext实例
//var audioCxt;
//动画
var audioAnimation;
//audioCxt = wx.createInnerAudioContext();
//audioCxt.src = 'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/audio/daziqin0.mp3';
var i = 100;
var j = 100;
Page({
  data: {
    play:10,
    isok:0,
    wHeight:60,
    left:50,
    top:0,
    width:100,
    pan:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/upload/202112221117122047.png',
    isdog:0,
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that =this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        // 屏幕宽度、高度
        console.log('height=' + res.windowHeight);
        console.log('width=' + res.windowWidth);
        // 高度,宽度 单位为px
        that.setData({
          windowHeight:  res.windowHeight,
          windowWidth:  res.windowWidth,
          //buttonTop1:buttonTop1,//这里定义按钮的初始位置
          //buttonLeft:res.windowWidth*0.70,//这里定义按钮的初始位置
        })
      }
    })
  },
  onLoad:function(){

    console.log('load i='+i+' j='+j+' top='+this.data.top+' width='+this.data.width)
  },
 
    //播放按钮事件
    playRight : function(e){
      var that = this;
      let play = e.currentTarget.dataset.play;
      if(i<650){
        //$('.paw').animate({left:'+=20px'},300);
        that.setData({
          left:that.data.left+20,
        })
        i+=20;
      }
      console.log('i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width)
    },
    playLeft : function(e){
      var that = this;
      let play = e.currentTarget.dataset.play;
      if(i>100){
        //$('.paw').animate({left:'+=20px'},300);
        that.setData({
          left:that.data.left-20,
        })
        i-=20;
      }
      console.log('i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width)
    },
    playTop : function(e){
      var that = this;
      let play = that.data.play;
      if(j>70){
        //$('.paw').animate({left:'+=20px'},300);
        that.setData({
          top:that.data.top+play,
          width:that.data.width-play,
        })
        j-=play;
      }
      console.log('playTop i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width)
    },
    playBottom : function(e){
      var that = this;
      let play = that.data.play;
      if(j<110){
        //$('.paw').animate({left:'+=20px'},300);
        that.setData({
          top:that.data.top-play,
          width:that.data.width+play,
        })
        j+=play;
      }
      console.log('playBottom i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width)
    },
    playOk:function(){
      var that = this;
      var isok = that.data.isok;
      var pan = that.data.pan;
      that.setData({
        wHeight:300,
      })

    setTimeout(function () {
      //要延时执行的代码
      if(i==400 && j==110){
       isok= 2;
       that.data.isdog = 2;
        pan = 'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/upload/202112221117126274.png';
        that.setData({
          isok:isok,
          isdog:that.data.isdog,
        })
        console.log('playOk 400 i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width+' isok='+isok)
      }
      else{
        isok= 1;
        that.data.isdog = 1;
      }
      that.setData({
        wHeight:50,
        pan:pan,
        isok:isok,
        isdog:that.data.isdog,
      })
      
     }, 300) //延迟时间 这里是1秒
     console.log('playOk i='+i+' j='+j+' top='+that.data.top+' width='+that.data.width+' isok='+isok)
    },
  //创建一个动画实例
  initAnimation:function(){
    var that = this;
    that.animation = wx.createAnimation({
       duration: 100,
       timingFunction: "ease",
       delay: 0,
       transformOrigin: 'center bottom',
       success: function (res) {
         console.log(res)
       }
    });
  },
  
  resetKey(){
    this.setData({
      isok:0,
    })
    // wx.redirectTo({
    //   url: '../lock/test4',
    // })
  },
  isOk(){
    let isok = this.data.isok;
    var words = isok.split(",");
    words = this.uniqueStr(words);
    isok = words.join(',');
    let tip = '再想想!';
    if(isok == '2,4,1,3,'){
      console.log('锁开了!')
      tip = '锁开了!';
    }
    else{
      console.log('2413再想想!'+ isok)
    }
    wx.showModal({
      title: '提示',
      content: tip,
      success: (res) => {
          // wx.switchTab({
          //   url: '/pages/strategyList/strategyList'
          // })                
      }
    })
  },

  uniqueStr (array){
    return array.filter(function(el, index, arr) {
    return index == arr.indexOf(el);
    });
  },

})